<?php
namespace App\Models\Trade\Sub;

use App\Models\Model;

class ValidityModel extends Model
{

    const TABLENAME = 'tw_trade_sub_validity';

    private static $field = ['day', 'time'];

    /**
     * 查询列表（所有数据）
     *
     * @return \Illuminate\Support\Collection
     */
    public static function selectAll()
    {
        return self::dbTable()->select(self::$field)
            ->orderBy('sort')
            ->get();
    }

    /**
     * 制作有效时间的时间戳
     *
     * @param \Illuminate\Support\Collection $collection            
     * @return array(array)
     */
    public static function makeDataListDecode($collection)
    {
        return $collection->map(function ($item, $key) {
            $item['valided'] = time() + $item['time'];
            return $item;
        })->toArray();
    }
}
